<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import temblorMacro from '@/api/temblor/temblorMacro'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()


const numberOperation = (newValue, id, numberName) => {
  temblorMacro.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  temblorMacro.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'temblor_macro',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: temblorMacro.getList,
  recycleApi: temblorMacro.getRecycleList,
  add: {
    show: true,
    api: temblorMacro.save,
    auth: ['temblor:macro:save']
  },
  edit: {
    show: true,
    api: temblorMacro.update,
    auth: ['temblor:macro:update']
  },
  delete: {
    show: true,
    api: temblorMacro.deletes,
    auth: ['temblor:macro:delete'],
    realApi: temblorMacro.realDeletes,
    realAuth: ['temblor:macro:realDeletes']
  },
  recovery: {
    show: true,
    api: temblorMacro.recoverys,
    auth: ['temblor:macro:recovery']
  },
  import: {
    show: true,
    url: 'temblor/macro/import',
    templateUrl: 'temblor/macro/downloadTemplate',
    auth: ['temblor:macro:import']
  },
  export: {
    show: true,
    url: 'temblor/macro/export',
    auth: ['temblor:macro:export']
  }
})

const columns = reactive([
  {
    title: "",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入"
    }
  },
  {
    title: "用户",
    dataIndex: "user_id",
    formType: "input"
  },
  {
    title: "异常位置",
    dataIndex: "location",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入异常位置"
    }
  },
  {
    title: "经度坐标",
    dataIndex: "latitude",
    formType: "input",
    search: true
  },
  {
    title: "纬度坐标",
    dataIndex: "longitude",
    formType: "input",
    search: true
  },
  {
    title: "异常类型",
    dataIndex: "abnormality_type",
    formType: "select",
    search: true,
    commonRules: {
      required: true,
      message: "请输入异常类型"
    },
    multiple: false,
    dict: {
      data: [
        {
          label: "动物",
          value: "1"
        },
        {
          label: "天空",
          value: "2"
        },
        {
          label: "地表",
          value: "3"
        },
        {
          label: "地下",
          value: "4"
        },
        {
          label: "其他",
          value: "5"
        }
      ],
      translation: true
    }
  },
  {
    title: "联系电话",
    dataIndex: "contact_phone",
    formType: "input",
    search: true
  },
  {
    title: "上报时间",
    dataIndex: "report_time",
    formType: "date",
    search: true,
    commonRules: {
      required: true,
      message: "请输入上报时间"
    },
    showTime: true
  },
  {
    title: "状态",
    dataIndex: "status",
    formType: "select",
    search: true,
    commonRules: {
      required: true,
      message: "请输入状态"
    },
    multiple: false,
    dict: {
      data: [
        {
          label: "待处理",
          value: "1"
        },
        {
          label: "已批准",
          value: "2"
        },
        {
          label: "已拒绝",
          value: "3"
        }
      ],
      translation: true
    }
  },
  {
    title: "",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  }
])
</script>
<script> export default { name: 'temblor:macro' } </script>